package dr.ihm;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.vecmath.Vector2f;

public class Bouton {
	/*Attributs*/
	private Vector2f position;/*position 2d de l'agent*/
	private int type;
	private float dureeSpawn;
	private float dureeMeurt;
	private long tempsStocke;
	private long temps;
	private float vitesse;
	private Vector2f direction;
	private float vitesseMem;
	
	/*Constructeur*/
	public Bouton(float x1, float y1, double x2, double y2, int type) {
		Vector2f pos=new Vector2f();
		pos.x=x1;
		pos.y=y1;
		
		Vector2f dir=new Vector2f();
		dir.x=(float)x2;
		dir.y=(float)y2;
		
		this.position=pos;
		this.direction=dir;
		this.type=type;
		this.dureeSpawn=1.25f;
		this.dureeMeurt=0.0f;
		this.tempsStocke=System.currentTimeMillis();
		this.temps=System.currentTimeMillis();
		this.vitesse=250.0f;
	}

	/*Getters & Setters*/
	public Vector2f getPosition() {
		return position;
	}
	public void setPosition(Vector2f position) {
		this.position = position;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public float getDureeSpawn() {
		return dureeSpawn;
	}
	public void setDureeSpawn(float dureeSpawn) {
		this.dureeSpawn = dureeSpawn;
	}
	public float getDureeMeurt() {
		return dureeMeurt;
	}
	public void setDureeMeurt(float dureeMeurt) {
		this.dureeMeurt = dureeMeurt;
	}
	public long getTempsStocke() {
		return tempsStocke;
	}
	public void setTempsStocke(long tempsStocke) {
		this.tempsStocke = tempsStocke;
	}
	public long getTemps() {
		return temps;
	}
	public void setTemps(long temps) {
		this.temps = temps;
	}
	public float getVitesse() {
		return vitesse;
	}
	public void setVitesse(float vitesse) {
		this.vitesse = vitesse;
	}
	public Vector2f getDirection() {
		return direction;
	}
	public void setDirection(Vector2f direction) {
		this.direction = direction;
	}
	public float getVitesseMem() {
		return vitesseMem;
	}
	public void setVitesseMem(float vitesseMem) {
		this.vitesseMem = vitesseMem;
	}

	public void seDessiner(Graphics2D g,int x,int y,BufferedImage texAgent){
			//g.rotate(90,(double)position.x,(double)position.y);
			g.drawImage(texAgent, x-40/2,y-40/2,40,40,null);
			//g.fillRect(x-20/2, y-20/2, 20, 20);
	}

	public void update(){
		temps=System.currentTimeMillis();
		vitesseMem=vitesse;
		vitesse*=(float)(temps-tempsStocke)/1000;
		if(dureeSpawn>0){
			//float vitesse =100*(float)(temps-tempsStocke)/1000;
			this.position.x+=vitesse*direction.x;
			this.position.y-=vitesse*direction.y;
			dureeSpawn-=(float)(temps-tempsStocke)/1000;
			vitesseMem-=500*(float)(temps-tempsStocke)/1000;
			if(vitesseMem<0){
				vitesseMem=0.0f;
			}
		}
		vitesse=vitesseMem;
		tempsStocke=temps;
	}
}